import { _decorator, Component, Node, Sprite } from 'cc';
import { SingleFood } from './SingleFood';
const { ccclass, property } = _decorator;

@ccclass('SinglePallet')
/**
 * 单个托盘
 */
export class SinglePallet extends Component {

    //托盘
    @property(Node)
    public Pallet: Node = null;

    //食物索引
    public FoodIndex: number[] = [-1, -1, -1, -1, -1, -1];

    //食物数量
    public FoodCount: number = 0;

    /**
     * 初始化盘子
     */
    public InitPlallet() {

    }

    /**
     * 隐藏
     */
    public IamHide() {
        this.Pallet.active = false;
    }

    /**
     * 更新显示
     */
    public UpdateShow() {
        for (let i = 0; i < this.FoodIndex.length; i++) {
            this.Pallet.getChildByName("foodnode").children[i].getComponent(SingleFood).UpdateFood(this.FoodIndex[i]);
        }
    }

    /**
     * 添加食物
     */
    public AddFoode(_index: number) {
        for (let i = 0; i < this.FoodIndex.length; i++) {
            if (this.FoodIndex[i] == -1) {
                this.FoodIndex[i] = _index;
                this.FoodCount = i + 1;
                this.UpdateShow();
                break;
            }
        }
    }

    /**
     * 返回我最后一个食物
     */
    public ReturnLastFood() {
        return this.FoodIndex[this.FoodCount - 1];
    }

    /**
     * 返回我得第一个食物
     */
    public ReturnFirstFood() {
        return this.FoodIndex[0];
    }

}


